﻿<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<link rel="stylesheet" type="text/css" href="css/login.css">
	<title></title>
</head>
<iframe id="head" src="heads.html" width="100%" height="" frameborder="0" scrolling="no"></iframe>
<body background="img/2.jpg">
	<div id="log">
		<h4>欢迎登录</h4>
		<p><input type="text" id="uname" placeholder="手机号/邮箱"></p>
		<p><input type="password" id="upwd" placeholder="请输入密码"></p>
		<p><button onclick="login()">登录</button></p>
		<p><span><a href="register.html">注册</a></span>&nbsp;<span><a href="">找回密码</a></span><span><a href="product_login.html">管理员登录</a></span></p>
	</div>

	<script>
		function login(){
			let _uname=uname.value;
			let _upwd=upwd.value;
			if(!_uname && _upwd){
				alert("输入不能为空！")
			}
			let xhr=new XMLHttpRequest();
			xhr.onreadystatechange=function(){
				if(xhr.readyState===4 && xhr.status===200){
					let r=xhr.responseText;
					if(r==="1"){
						alert("登录成功！");
						location.href=`user_page.html?uname=${_uname}`;
					}else{
						alert("登录失败，请检查用户名或密码");
					}
				}
			}
			xhr.open("POST","user/login",true);
			let formdata=`uname=${_uname}&upwd=${_upwd}`;
			xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			xhr.send(formdata);
		}
	</script>

</body>
</html>